import { Body, Controller, Get, Post, Query } from "@nestjs/common";
import { CreateLog, Roles } from "@/common/decorators";
import { Role } from "@/common/enum/role.enum";
import { RequiredPipe } from "@/common/pipes/required.pipe";
import { SysCascaderType } from "@/database/entity/SysCascaderType";
import { CascaderTypeService } from "./csdr-type.service";
import { CreateCascaderTypeDto } from "./dto/create-csdr-type.dto";
import { PageCascaderTypeDto } from "./dto/page-csdr-type.dto";
import { UpdateCascaderTypeDto } from "./dto/update-csdr-type.dto";

@Controller("sys/cascaderType")
export class CascaderTypeController {
    constructor(private readonly cascaderTypeService: CascaderTypeService) {}

    /** 新增级联字典 */
    @CreateLog({ module: "系统字典", type: "create", action: "创建级联字典" }, SysCascaderType)
    @Roles(Role.SUPER_ADMIN)
    @Post("create")
    async create(@Body() data: CreateCascaderTypeDto) {
        return this.cascaderTypeService.create(data);
    }

    /** 删除级联字典 */
    @CreateLog({ module: "系统字典", type: "delete", action: "删除级联字典" }, SysCascaderType)
    @Roles(Role.SUPER_ADMIN)
    @Post("remove")
    async remove(@Body("id", RequiredPipe) id: string) {
        return this.cascaderTypeService.remove(id);
    }

    /** 更新级联字典 */
    @CreateLog({ module: "系统字典", type: "update", action: "更新级联字典" }, SysCascaderType)
    @Roles(Role.SUPER_ADMIN)
    @Post("update")
    async update(@Body() data: UpdateCascaderTypeDto) {
        return this.cascaderTypeService.update(data);
    }

    /** 根据 id 查询级联字典 */
    @Get("findById")
    async findById(@Query("id", RequiredPipe) id: string) {
        return this.cascaderTypeService.findById(id);
    }

    /** 获取级联字典分页列表 */
    @Post("page")
    async page(@Body() data: PageCascaderTypeDto) {
        return this.cascaderTypeService.page(data);
    }
}
